<template>
    <div class="common-box" v-if="boxIsShow">
        <div class="common-content-box">
            <div class="common-content-top-box">
                <div class="form_box">
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                        <el-form-item label="扣子Token" prop="money">
                            <el-input type="text" v-model="ruleForm.cozeToken"></el-input>
                        </el-form-item>
                        <el-form-item label="扣子Botid" prop="point">
                            <el-input type="text" v-model="ruleForm.cozeBotid"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
            <div class="common-content-top-box">
              <div class="form_box">
                  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                      <el-form-item label="飞影极速时长">
                          <el-input type="text" v-model="fy.js" :disabled="true"></el-input>
                      </el-form-item>
                      <el-form-item label="飞影专业时长">
                          <el-input type="text" v-model="fy.zy" :disabled="true"></el-input>
                      </el-form-item>
                      <el-form-item>
                          <el-button type="primary" @click="shuaxin">刷新</el-button>
                      </el-form-item>
                  </el-form>
              </div>
          </div>
        </div>
    </div>
</template>
<script>
export default {
  data() {
    return {
        uploadNum:1,
        boxIsShow:false,
        fy:{
          js:0,
          zy:0
        },
        ruleForm: {
            cozeToken:'',
            cozeBotid:''
        },
        rules: {
            cozeToken: [
                { required: true, message: '请输入扣子Token', trigger: ["blur,change"] }
            ],
            cozeBotid: [
                { required: true, message: '请输入扣子Botid', trigger: ["blur,change"] }
            ]
        },
    };
  },
  created() {
    
  },
  mounted(){
    this.__init();
  },
  methods: {
    __init() {
      this.getDataList();
      this.getFeiYinUserData();
    },
    getDataList(){
      var url="manager/getSystemSetConfig";
      var params={}
      this.$post(url, params).then((res) => {
        console.log(res)
        if (res.code === 200) {
            this.ruleForm={
                cozeToken:res.data.cozeToken,
                cozeBotid:res.data.cozeBotid
            }
        } else {
          this.$message.error(res.msg)
        }
      });
    },
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
            if (valid) {
                var url="manager/setSystemSetConfig";
                var params={
                    ...this.ruleForm
                }
                this.$post(url, params).then((res) => {
                    console.log(res)
                    if (res.code === 200) {
                        this.$message.success('操作成功')
                        this.getDataList();
                        this.resetForm('ruleForm');
                    } else {
                        this.$message.error(res.msg)
                    }
                });
            } else {
                console.log('error submit!!');
                return false;
            }
        });
    },
    shuaxin(){
      this.getFeiYinUserData();
    },
    getFeiYinUserData(){
      const xhr = new XMLHttpRequest();
      const url = "https://aip.1laigc.com/api/oem-get-account-info";  // 替换实际接口地址
      const params = {oem_uid:"07402425367fdf7931212f"}; // 替换实际请求参数

      xhr.open('GET', url + '?' + new URLSearchParams(params), true);
      
      xhr.onload = () => {
        if (xhr.status >= 200 && xhr.status < 300) {
          const res = JSON.parse(xhr.responseText);
          if (res.code === 20000) {
            console.log(res.data);
            this.fy={
              js:0,
              zy:0
            };
          } else {
            this.$message.error(res.msg);
          }
        } else {
          this.$message.error(`请求失败：${xhr.statusText}`);
        }
      };
      
      xhr.onerror = () => {
        this.$message.error('网络请求异常');
      };
      
      xhr.send();
    }
  }
}
</script>
<style scoped lang="scss">
  .common-box{
    background-color: #f9f9fb;
    height: 100%;
    position: relative;
  }
  .common-content-box{
    height: 95%;
    margin-top: 2%;
    width: 96%;
    display: inline-block;
  }
  .common-content-top-box{
    width: 100%;
    background-color: #fff;
    min-height: 200px;
    box-shadow: 1px 1px 6px 2px rgba(0,0,0,0.1);
    border-radius: 5px;
    text-align: left;
    margin-bottom: 30px;
  }
  .form_box{
    margin-left: 20px;
    margin-top: 25px;
    width: 40%;
    display: inline-block;
  }
  .common-content-bottom-box{
    width: 100%;
    background-color: #fff;
    min-height: 200px;
    box-shadow: 1px 1px 6px 2px rgba(0,0,0,0.1);
    border-radius: 5px;
    margin-top: 30px;
    padding: 20px 0;
  }
  .table_box{
    width: 96%;
    margin-left: 2%;
  }
</style>